package com.yztc.orangeentertainment.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.facebook.drawee.view.DraweeView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.yztc.orangeentertainment.R;
import com.yztc.orangeentertainment.bean.channalbean.ListBean;
import com.yztc.orangeentertainment.utils.DividerItemDecoration;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by My on 2016/10/7.
 */
public class MyChannalContentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private List<ListBean> listBeanList;

    public MyChannalContentAdapter(Context context, List<ListBean> listBeanList) {
        this.context = context;
        this.listBeanList = listBeanList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == ITEM_TYPE.ITEM_TYPE_normal.ordinal()) {

            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.channal_content_rvitem1, parent,
                    false);

            return new MyViewHOlder1(view);

        } else if (viewType == ITEM_TYPE.ITEM_TYPE_HS.ordinal()) {

            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout
                    .channal_content_rvhead, parent, false);
            return new MyViewHolder(view);

        } else if (viewType == ITEM_TYPE.ITEM_TYPE_pingfen.ordinal()) {

            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout
                    .channal_content_rvitem2, parent, false);
            return new MYViewHolder2(view);

        } else if (viewType == ITEM_TYPE.ITEM_TYPE_gif.ordinal()) {

            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout
                    .channal_content_rvitem4, parent, false);
            return new MYViewHolder4(view);

        } else if (viewType == ITEM_TYPE.ITEM_TYPE_video.ordinal()) {

            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout
                    .channal_content_rvitem3, parent, false);
            return new MYViewHolder3(view);

        }

        return null;
    }

    @Override
    public int getItemViewType(int position) {

        return ITEM_TYPE.ITEM_TYPE_normal.ordinal();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyViewHOlder1) {
            Glide.with(context).load(listBeanList.get(position).getPic()).into(((MyViewHOlder1) holder)
                    .ivChannalrvitem1photo);
            ((MyViewHOlder1) holder).tvChannalrvitem1title.setText(listBeanList.get(position).getTitle());
            if(listBeanList.get(position).getCat()!=null&&!"".equals(listBeanList.get
                    (position).getCat())) {
                Glide.with(context).load(listBeanList.get(position).getCat().getIcon()).into((
                        (MyViewHOlder1) holder).dvChannalrvitem1icon);
                ((MyViewHOlder1) holder).tvChannalrvitem1type.setText(listBeanList.get(position)
                        .getCat().getName());
            }
            ((MyViewHOlder1) holder).tvChannalrvitem1scanner.setText(listBeanList.get(position)
                    .getReadnum()+"");

        }

    }

    @Override
    public int getItemCount() {
        return listBeanList.size();
    }

    public static enum ITEM_TYPE {
        ITEM_TYPE_HS,
        ITEM_TYPE_normal,
        ITEM_TYPE_pingfen,
        ITEM_TYPE_gif,
        ITEM_TYPE_video
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.dv_image)
        SimpleDraweeView dvImage;
        @InjectView(R.id.tv_channalvpheadtitle)
        TextView tvChannalvpheadtitle;
        @InjectView(R.id.tv_channalvpheadseemore)
        TextView tvChannalvpheadseemore;
        @InjectView(R.id.rv_channalvphead)
        RecyclerView rvChannalvphead;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
            //水平摆放
            linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
            //间距
            rvChannalvphead.addItemDecoration(new DividerItemDecoration(20));
            rvChannalvphead.setLayoutManager(linearLayoutManager);
        }
    }

    static class MyViewHOlder1 extends RecyclerView.ViewHolder {
        @InjectView(R.id.tv_channalrvitem1title)
        TextView tvChannalrvitem1title;
        @InjectView(R.id.dv_channalrvitem1icon)
        DraweeView dvChannalrvitem1icon;
        @InjectView(R.id.tv_channalrvitem1type)
        TextView tvChannalrvitem1type;
        @InjectView(R.id.iv_channalrvitem1scanner)
        ImageView ivChannalrvitem1scanner;
        @InjectView(R.id.tv_channalrvitem1scanner)
        TextView tvChannalrvitem1scanner;
        @InjectView(R.id.iv_channalrvitem1delete)
        ImageView ivChannalrvitem1delete;
        @InjectView(R.id.iv_channalrvitem1photo)
        ImageView ivChannalrvitem1photo;

        public MyViewHOlder1(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
            tvChannalrvitem1scanner= (TextView) itemView.findViewById(R.id.tv_channalrvitem1scanner);
        }
    }

    static class MYViewHolder2 extends RecyclerView.ViewHolder {
        @InjectView(R.id.iv_channalrvitem2)
        ImageView ivChannalrvitem2;
        @InjectView(R.id.tv_channalrvitem2title)
        TextView tvChannalrvitem2title;
        @InjectView(R.id.tv_channalrvitem2program)
        TextView tvChannalrvitem2program;
        @InjectView(R.id.sb_channalrvitem2)
        SeekBar sbChannalrvitem2;
        @InjectView(R.id.btn_channalrvitem2)
        Button btnChannalrvitem2;

        public MYViewHolder2(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }

    static class MYViewHolder3 extends RecyclerView.ViewHolder {
        @InjectView(R.id.vv_channalrvitem3)
        ImageView vvChannalrvitem3;
        @InjectView(R.id.tv_channalrvitem3title)
        TextView tvChannalrvitem3title;
        @InjectView(R.id.iv_channalrvitem3icon)
        ImageView ivChannalrvitem3icon;
        @InjectView(R.id.tv_channalrvitem3icon)
        TextView tvChannalrvitem3icon;
        @InjectView(R.id.iv_channalrvitem3scanner)
        ImageView ivChannalrvitem3scanner;
        @InjectView(R.id.tv_channalrvitem3scanner1)
        TextView tvChannalrvitem3scanner;

        public MYViewHolder3(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }

    static class MYViewHolder4 extends RecyclerView.ViewHolder {
        @InjectView(R.id.gv_channalrvitem4)
        ImageView gvChannalrvitem4;
        @InjectView(R.id.tv_channalrvitem4title)
        TextView tvChannalrvitem4title;
        @InjectView(R.id.tv_channalrvitem4name)
        TextView tvChannalrvitem4name;
        @InjectView(R.id.iv_channalrvitem4share)
        Button ivChannalrvitem4share;

        public MYViewHolder4(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }
}
